package logger

import (
	"bytes"
	"fmt"
	"github.com/sirupsen/logrus"
)

type DefaultFieldHook struct {

}

func (hook *DefaultFieldHook) Levels() []logrus.Level {
	return logrus.AllLevels
}

func (*DefaultFieldHook) Fire(entry *logrus.Entry) error {
	return nil
}

type DefaultFormatter struct {}

func (f *DefaultFormatter) Format(entry *logrus.Entry) ([]byte, error) {
	buffer := bytes.Buffer{}
	buffer.WriteString(fmt.Sprintf(
		"[%s][%s]%s (%s:%d)",
		entry.Time.Format("2006-01-02 15:04:05"),
		entry.Level,
		entry.Message,
		entry.Caller.File,
		entry.Caller.Line,
	))
	buffer.WriteString("\n")
	if len(entry.Data) > 0 {
		for k, v := range entry.Data {
			buffer.WriteString(fmt.Sprintf("\t%s = %v\n", k, v))
		}
	}
	return buffer.Bytes(), nil
}